package com.exigen.perflabstat.dao.jpa;

import java.util.List;

import javax.persistence.Query;

import com.exigen.perflabstat.base.GenericJPADAO;
import com.exigen.perflabstat.dao.ScenarioTypeDao;
import com.exigen.perflabstat.models.ScenarioType;

public class ScenarioTypeJpaDao extends GenericJPADAO<ScenarioType, Long> implements ScenarioTypeDao {

	public ScenarioTypeJpaDao() {
		super(ScenarioType.class);
	}

	@SuppressWarnings("unchecked")
	public List<ScenarioType> allScenarioTypes() {
		
		Query query = getEntityManager().createQuery("from ScenarioType");
		
		List<ScenarioType> result = query.getResultList();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public ScenarioType findByScenarioType(String scenarioTypeName) {

		ScenarioType scenarioType = null;
		
		Query query = getEntityManager().createQuery("select scenarioType from ScenarioType scenarioType where scenarioType.SCENARIO_TYPE_NAME = :scenarioTypeName");
		query.setParameter("scenarioTypeName", scenarioTypeName);
		query.setMaxResults(1);
		
		List<ScenarioType> result = query.getResultList();
		
		if(result.isEmpty())return null;
		
		scenarioType = result.get(0);
		
		return scenarioType;
	}
	
}
